const app = getApp()
const imgUrl =app.globalData.imgUrl
const shareUtil = require('../../../utils/shareUtil.js');
Page({
    data: {
        imageInfo: [],
        imageUrls: [],
        imgUrl:imgUrl
    },
    compressImg: function(e, t) {
        wx.compressImage({
            src: e,
            quality: 40,
            success: function(e) {
                t(e.tempFilePath);
            },
            fail: function(a) {
                t(e);
            }
        });
    },
    previewImage: function(e) {
        var a = this;
        wx.chooseImage({
            count: 9,
            success: function(e) {
                for (var i = 0; i < e.tempFilePaths.length; i++) 
                a.getImageInfo(e.tempFilePaths[i]), 
                a.compressImg(e.tempFilePaths[i], function(e) {
                });
            }
        });
    },
    getImageInfo: function(e) {
        var t = this;
        wx.getImageInfo({
            src: e,
            success: function(a) {
                var i = t.data.imageInfo, n = t.data.imageUrls, s = new Object();
                s.url = e, s.width = a.width, s.height = a.height, i.push(s), n.push(e), t.setData({
                    imageInfo: i,
                    imageUrls: n
                });
            }
        });
    },
    removeImage: function(e) {
        var t = this.data.imageInfo, a = this.data.imageUrls, i = e.currentTarget.dataset.myindex;
        t.splice(i, 1), a.splice(i, 1), 
        this.setData({
            imageInfo: t,
            imageUrls: a
        });
    },
    changePreview: function(e) {
        wx.previewImage({
            current: e.currentTarget.dataset.src,
            urls: this.data.imageUrls
        });
    },
    chooseDiretion: function() {
        null != this.data.imageInfo[8] ? wx.navigateTo({
            url: "./showImage?imageInfo=" + JSON.stringify(this.data.imageInfo)
        }) : wx.showToast({
            title: "要选九张图！",
            icon: "none"
        });
    },
    onShareAppMessage:shareUtil.shareConfig,
    onShareTimeline:shareUtil.shareConfig,
});